package cn.ex.ymcc.controller;


import cn.ex.ymcc.doc.CourseDoc;
import cn.ex.ymcc.vo.CourseQueryDto;
import cn.ex.ymcc.result.JSONResult;
import cn.ex.ymcc.result.PageList;
import cn.ex.ymcc.service.ICourseESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class ESCourseController {


    @Autowired
    private ICourseESService courseESService;

    /**
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/onLineCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseESService.onLineCourse(doc);
        return JSONResult.success();
    }

    /**
     * 课程下线
     * @param courseId
     * @return
     */
    @GetMapping("/offLineCourse/{courseId}}")
    public JSONResult offLineCourse(@PathVariable("courseId") Long courseId){
        courseESService.offLineCourse(courseId);
        return JSONResult.success();
    }



    /**
     * 课程列表  Es分页查询
     * @param dto
     * @return
     */
    @PostMapping("/course/search")
    public PageList<CourseDoc> search(@RequestBody CourseQueryDto dto){
        return courseESService.searchCourse(dto);
    }

}
